import Vue from 'vue';
import VueRouter from 'vue-router';
import Layout from '@/components/layout/layout';
import Login from '@/views/login/index';
import menus from './menu';
import exception from './exception';
// import { useCheckUserPermission } from '@/middleware/middleware';

Vue.use(VueRouter);

const routes = [
  {
    path: '/index',
    name: 'index',
    component: Layout,
    children: [...exception],
  },
  {
    path: '/',
    name: 'login',
    component: Login,
  },
  {
    path: '/suser',
    name: 'home',
    component: Layout,
    children: [...menus],
    // redirect: '/suser',
  },
  // {
  //   path: '/qwe',
  //   name: 'qwe',
  //   component: () => import('@/views/articles/article'),
  // },
  {
    path: '/showRoom',
    name: 'showRoom',
    meta: { title: '3DVR展厅', icon: 'work' },
    component: () => import('@/views/museum/showRoom'),
  },
];

const router = new VueRouter({
  mode: 'hash',
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
});

const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

VueRouter.prototype.replace = function push(location) {
  return originalReplace.call(this, location).catch((err) => err);
};
export default router;
